const InspectModel = require('../models/inspectModel')

// 检查内务的控制层
class InspectController {
    // 内务检查记录添加
    static async add(req, res) {
        let { inspect_num, type, class_id, inspect_date, inspecter, del_score, comment, project } = req.body
        let score = 100 - Number(del_score)
        try {
            let results = await InspectModel.add(inspect_num, type, class_id, inspect_date, inspecter, score, del_score, comment,
                project)
            console.log(results)
            res.json({ code: 0, msg: "内务检查记录添加成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 内务检查记录软删除
    static async del_f(req, res) {
        let { id } = req.query
        try {
            let results = await InspectModel.del_f(id)
            console.log(results)
            res.json({ code: 0, msg: "内务检查记录软删除成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 内务检查记录真删除
    static async del_t(req, res) {
        let { id } = req.query
        try {
            let results = await InspectModel.del_t(id)
            console.log(results)
            res.json({ code: 0, msg: "内务检查记录真删除成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 内务检查记录获取数据
    static async get(req, res) {
        let { id } = req.query
        try {
            let results = await InspectModel.get(id)
            console.log(results)
            res.json({ code: 0, msg: "内务检查记录真删除成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 内务检查记录设置数据
    static async set(req, res) {
        let { inspect_num, type, class_id, inspect_date, inspecter, del_score, comment, project, id } = req.body
        let score = 100 - Number(del_score)
        try {
            let results = await InspectModel.set(inspect_num, type, class_id, inspect_date, inspecter, score, del_score, comment, project, id)
            console.log(results)
            res.json({ code: 0, msg: "内务检查记录设置数据成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 内务检查记录列表搜索数据获取
    static async list(req, res) {
        let { inspect_num, type, class_id, program_id, inspect_date, page, page_size } = req.query
        try {
            let results = await InspectModel.list(inspect_num, type, class_id, program_id, inspect_date, Number(page),
                Number(page_size))
            console.log(results)
            res.json({ code: 0, msg: "内务检查记录列表搜索数据获取成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 获取所有房间号
    static async allRoomId(req, res) {
        try {
            let results = await InspectModel.allRoomId()
            console.log(results)
            res.json({ code: 0, msg: "获取所有房间号数据获取成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
}

module.exports = InspectController